package logic

import (
	"api/pkg"
	"cart_srv/cart_srv"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClearCartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewClearCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClearCartLogic {
	return &ClearCartLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ClearCartLogic) ClearCart(req *types.ClearCartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	cart, err := l.svcCtx.CartSrv.ClearCart(l.ctx, &cart_srv.ClearCartRequest{UserId: int64(req.UserId)})
	if err != nil {
		return &types.Response{
			Message: pkg.Sting(err.Error()),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "清空成功",
		Code:    200,
		Data:    cart,
	}, nil
}
